package ai.minimax;

import hexgame.GameState;
import hexgame.HexMove;
import hexgame.HexPlayer;

public class MiniMaxThread implements Runnable {
	GameState state;
	HexMove[] moves;
	int depth;
	boolean bridging;
	
	HexMove result;
	int score;
	
	public MiniMaxThread(GameState state, HexMove[] moves, int depth, boolean bridging) {
		this.state = state;
		this.moves = moves;
		this.depth = depth;
		this.bridging = bridging;
		
		this.score = Integer.MAX_VALUE;
	}
	
	@Override
	public void run() {
		for(HexMove move : moves) {
			int newScore = MiniMaxAI.miniMax(new HexMove(move.getX(), move.getY(), HexPlayer.RED_LOCAL), depth - 1, state, false, depth, bridging, Integer.MIN_VALUE, Integer.MAX_VALUE);
			
			if(score > newScore) {
				score = Math.min(score,  newScore);
				result = move;
			}
		}
	}
	
	public int getScore() {
		return score;
	}
	
	public HexMove getMove() {
		return result;
	}

}
